global input "Q:\dc1prhcmsas01\PU2\data - sas"
global temp "Q:\dc1prhcmsas01\PU2\temp_stata_wr"
global log "Q:\dc1prhcmsas01\PU2\Log - Stata WR"
global output "Q:\dc1prhcmsas01\PU2\data_stata_wr"
global graphs "Q:\dc1prhcmsas01\PU2\graphs_stata_wr"
global tables "Q:\dc1prhcmsas01\PU2\tables_stata_wr"

cd "Q:\dc1prhcmsas01\PU2\Code - Stata WR"
set scheme plotplain
graph set window fontface "Times New Roman"

capture log close
log using "$log/11_table_did_hires", replace

*Program to estimate regressions
cap program drop save_est
program define save_est 
args name var start

	*Save estimates
	use  "$output/`name'_estimates.dta", clear
	gen se=(ub-beta)/1.96
	keep if event_time==6
	
	local index = `start'
	foreach spec in Basic Within-Firm {
		preserve 
		keep if spec=="`spec'"
		
		*Regression Coefficients
		sum beta
		global b`index'_`var'=round(r(mean), 0.001)
		sum se
		global se`index'_`var'=round(r(mean),0.001)
		
		*Baseline characteristics
		sum n
		global n`index'_`var'=string(r(mean), "%10.0fc")
		
		restore 
		local ++index
	}
end 


*Table II
save_est fig7_log_base base 1
save_est fig7_log_base_recent base 3
save_est fig7_log_base_balanced base 7

save_est figA5_diff_base diff 1
save_est figA5_diff_base_recent diff 3
save_est figA5_diff_base_balanced diff 7

save_est fig7b_log_base_future fut 5
save_est fig7b_log_base_future_zeros fut 6
save_est fig7b_log_base_future_balanced fut 7

save_est fig7b_wage_growth growth 5
save_est fig7b_wage_growth_zeros growth 6
save_est fig7b_wage_growth_balanced growth 7

	capture erase "$tables/table2.tex"
	file open fh3 using "$tables/table2.tex", write replace

	file write fh3 ///
		"\begin{tabular}{@{\hskip\tabcolsep\extracolsep\fill} l cc cc cc cc cc cc cc cc}" _n ///
		"\toprule" _n ///
		"&& (1) && (2) && (3) && (4) && (5) && (6) && (7) && (8) \\" _n ///
		"\midrule" _n ///
		"Log Base Pay in Previous Job && $b1_base && $b2_base && $b3_base && $b4_base && && && $b7_base && $b8_base  \\" _n ///
		" && ($se1_base) && ($se2_base) && ($se3_base) && ($se4_base) && && && ($se7_base) && ($se8_base) \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay from Prev. Job && $b1_diff && $b2_diff && $b3_diff && $b4_diff && && && $b7_diff && $b8_diff  \\" _n ///
		" && ($se1_diff) && ($se2_diff) && ($se3_diff) && ($se4_diff) && && && ($se7_diff) && ($se8_diff) \\" _n ///
		"[1em] \\" _n ///
		"Log Base Pay After 18 Months && && &&  &&  && $b5_fut && $b6_fut && $b7_fut && $b8_fut   \\" _n ///
		" && &&  && && && ($se5_fut) && ($se6_fut)  && ($se7_fut) && ($se8_fut)   \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay After 18 Months && && &&  &&  && $b5_growth && $b6_growth && $b7_growth && $b8_growth   \\" _n ///
		" && &&  && && && ($se5_growth) && ($se6_growth)  && ($se7_growth) && ($se8_growth)   \\" _n ///
		"\midrule" _n ///
		"Bin FE 		  && Y && Y && Y && Y && Y && Y && Y && Y  \\" _n ///
		"Hire Date FE 	  && Y && Y && Y && Y && Y && Y && Y && Y  \\" _n ///
		"Firm-Date FE 	  && - && Y && - && Y && - && - && - && Y  \\" _n ///
		"N && $n1_base && $n2_base && $n3_base && $n4_base && $n5_fut && $n6_fut && $n7_base && $n8_base \\" _n ///
		"Sample	  && Any Past && Any Past  &&  6 Month Past  && 6 Month Past  && Any Post && Fill Missing && Balanced && Balanced \\" _n ///
		"\bottomrule" _n ///
		"\end{tabular}" _n
		
	file close fh3 
	macro drop fh3 

	capture erase "$tables/table2_short.tex"
	file open fh3 using "$tables/table2_short.tex", write replace

	file write fh3 ///
		"\begin{tabular}{@{\hskip\tabcolsep\extracolsep\fill} l cc cc cc cc}" _n ///
		"\toprule" _n ///
		"&& (1) && (2) && (3) && (4)  \\" _n ///
		"\midrule" _n ///
		"Log Base Pay in Previous Job && $b1_base && $b3_base && && $b7_base  \\" _n ///
		" && ($se1_base) && ($se3_base) && && ($se7_base) \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay from Prev. Job && $b1_diff && $b3_diff && && $b7_diff  \\" _n ///
		" && ($se1_diff)  && ($se3_diff) && && ($se7_diff) \\" _n ///
		"[1em] \\" _n ///
		"Log Base Pay After 18 Months  &&  &&  && $b5_fut && $b7_fut  \\" _n ///
		"  && && && ($se5_fut) && ($se7_fut)   \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay After 18 Months  &&  &&  && $b5_growth$b7_growth  \\" _n ///
		"  && && && ($se5_growth) && ($se7_growth)  \\" _n ///
		"\midrule" _n ///
		"Bin FE 		  && Y && Y && Y && Y  \\" _n ///
		"Hire Date FE 	  && Y && Y && Y && Y  \\" _n ///
		"N && $n1_base && $n3_base && $n5_fut && $n7_base \\" _n ///
		"Sample	  && Any Past  &&  6 Month Past  && Any Post && Balanced \\" _n ///
		"\bottomrule" _n ///
		"\end{tabular}" _n
		
	file close fh3 
	macro drop fh3 

	
*Table II - other outcomes
save_est fig7_salaried base 1
save_est fig7_salaried_recent base 3

save_est fig7_months diff 1
save_est fig7_months_recent diff 3

save_est fig7_observe observe 1
save_est fig7_observe_recent observe 3

save_est fig7b_observe_future fut 5


	capture erase "$tables/table2_extra.tex"
	file open fh3 using "$tables/table2_extra.tex", write replace

	file write fh3 ///
		"\begin{tabular}{@{\hskip\tabcolsep\extracolsep\fill} l cc cc cc cc cc cc}" _n ///
		"\toprule" _n ///
		"&& (1) && (2) && (3) && (4) && (5) && (6) \\" _n ///
		"\midrule" _n ///
		"Salaried in Previous Job && $b1_base && $b2_base && $b3_base && $b4_base && &&  \\" _n ///
		" && ($se1_base) && ($se2_base) && ($se3_base) && ($se4_base) && &&  \\" _n ///
		"[1em] \\" _n ///
		"Months Since Previous Job  && $b1_diff && $b2_diff && $b3_diff && $b4_diff && &&   \\" _n ///
		" && ($se1_diff) && ($se2_diff) && ($se3_diff) && ($se4_diff) && && \\" _n ///
		"[1em] \\" _n ///
		"Probability Observe Previous Job  && $b1_observe && $b2_observe && $b3_observe && $b4_observe && &&  \\" _n ///
		" && ($se1_observe) && ($se2_observe) && ($se3_observe) && ($se4_observe) &&  && \\" _n ///
		"[1em] \\" _n ///
		"Probability Observe Future Job && && &&  &&  && $b5_fut && $b6_fut    \\" _n ///
		" && &&  && && && ($se5_fut) && ($se6_fut)  \\" _n ///
		"\midrule" _n ///
		"Bin FE 		  && Y && Y && Y && Y && Y && Y   \\" _n ///
		"Hire Date FE 	  && Y && Y && Y && Y && Y && Y  \\" _n ///
		"Firm-Date FE 	  && - && Y && - && Y && - && Y  \\" _n ///
		"N && $n1_observe && $n2_observe && $n3_observe && $n4_observe && $n5_fut && $n6_fut  \\" _n ///
		"Sample	  && Any Past && Any Past  &&  6 Month Past  && 6 Month Past  && Any Post && Any Post \\" _n ///
		"\bottomrule" _n ///
		"\end{tabular}" _n
		
	file close fh3 
	macro drop fh3 


*Table II
save_est fig7_log_base base 1
save_est fig7_log_base_balanced base 5

save_est figA5_diff_base diff 1
save_est figA5_diff_base_balanced diff 5

save_est fig7b_log_base_future fut 3
save_est fig7b_log_base_future_balanced fut 5

save_est fig7b_wage_growth growth 3
save_est fig7b_wage_growth_balanced growth 5

	capture erase "$tables/table2_fe.tex"
	file open fh3 using "$tables/table2_fe.tex", write replace

	file write fh3 ///
		"\begin{tabular}{@{\hskip\tabcolsep\extracolsep\fill} l cc cc cc cc cc cc}" _n ///
		"\toprule" _n ///
		"&& (1) && (2) && (3) && (4) && (5) && (6) \\" _n ///
		"\midrule" _n ///
		"Log Base Pay in Previous Job && $b1_base && $b2_base &&  &&  && $b5_base && $b6_base  \\" _n ///
		" && ($se1_base) && ($se2_base) &&  &&  && && && ($se5_base) && ($se6_base) \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay from Prev. Job && $b1_diff && $b2_diff && &&  && $b5_diff && $b6_diff  \\" _n ///
		" && ($se1_diff) && ($se2_diff) &&  && && ($se5_diff) && ($se6_diff) \\" _n ///
		"[1em] \\" _n ///
		"Log Base Pay After 18 Months && && &&  $b3_fut && $b4_fut && $b5_fut && $b6_fut   \\" _n ///
		" && &&  && && && ($se3_fut) && ($se4_fut)  && ($se5_fut) && ($se6_fut)   \\" _n ///
		"[1em] \\" _n ///
		"\% $\Delta$ Base Pay After 18 Months && && &&  $b3_growth && $b4_growth && $b5_growth && $b6_growth   \\" _n ///
		" && &&  && ($se3_growth) && ($se4_growth)  && ($se5_growth) && ($se6_growth)   \\" _n ///
		"\midrule" _n ///
		"Bin FE 		  && Y && Y && Y && Y && Y && Y  \\" _n ///
		"Hire Date FE 	  && Y && Y && Y && Y && Y && Y  \\" _n ///
		"Firm-Date FE 	  && - && Y && - && Y && - && Y  \\" _n ///
		"N && $n1_base && $n2_base && $n3_fut && $n4_fut && $n5_base && $n6_base \\" _n ///
		"Sample	  && Any Past && Any Past  && Any Post && Any Post && Balanced && Balanced \\" _n ///
		"\bottomrule" _n ///
		"\end{tabular}" _n
		
	file close fh3 
	macro drop fh3 
	
log close
